﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Utility.Helper
{
    public static class MimeTypeExtension
    {
        public static string GetFileStreamExtensionName(this FileStream fs)
            =>  fs.Name[fs.Name.LastIndexOf(".")..];

        public static string GetFileExtensionName(this string orgName)
            => Path.GetExtension(orgName);


        /// <summary>
        /// 通过文件后缀获取资源的媒体类型
        /// </summary>
        public static string GetWebContentType(this string stuffix)
        {
            string content = "";
            switch (stuffix)
            {
                case ".*": content = "application/octet-stream"; break;
                case ".001": content = "application/x-001"; break;
                case ".323": content = "text/h323"; break;
                case ".907": content = "drawing/907"; break;
                case ".acp": content = "audio/x-mei-aac"; break;
                case ".aif": content = "audio/aiff"; break;
                case ".aiff": content = "audio/aiff"; break;
                case ".asa": content = "text/asa"; break;
                case ".asp": content = "text/asp"; break;
                case ".au": content = "audio/basic"; break;
                case ".awf": content = "application/vnd.adobe.workflow"; break;
                case ".bmp": content = "application/x-bmp"; break;
                case ".c4t": content = "application/x-c4t"; break;
                case ".cal": content = "application/x-cals"; break;
                case ".cdf": content = "application/x-netcdf"; break;
                case ".cel": content = "application/x-cel"; break;
                case ".cg4": content = "application/x-g4"; break;
                case ".cit": content = "application/x-cit"; break;
                case ".cml": content = "text/xml"; break;
                case ".cmx": content = "application/x-cmx"; break;
                case ".crl": content = "application/pkix-crl"; break;
                case ".csi": content = "application/x-csi"; break;
                case ".cut": content = "application/x-cut"; break;
                case ".dbm": content = "application/x-dbm"; break;
                case ".dcd": content = "text/xml"; break;
                case ".der": content = "application/x-x509-ca-cert"; break;
                case ".dib": content = "application/x-dib"; break;
                case ".doc": content = "application/doc"; break;
                case ".docx": content = "application/doc"; break;
                case ".drw": content = "application/x-drw"; break;
                case ".dwg": content = "application/x-dwg"; break;
                case ".dxf": content = "application/x-dxf"; break;
                case ".emf": content = "application/x-emf"; break;
                case ".ent": content = "text/xml"; break;
                case ".eps": content = "application/x-ps"; break;
                case ".etd": content = "application/x-ebx"; break;
                case ".fax": content = "image/fax"; break;
                case ".fif": content = "application/fractals"; break;
                case ".frm": content = "application/x-frm"; break;
                case ".gbr": content = "application/x-gbr"; break;
                case ".gif": content = "image/gif"; break;
                case ".gp4": content = "application/x-gp4"; break;
                case ".hmr": content = "application/x-hmr"; break;
                case ".hpl": content = "application/x-hpl"; break;
                case ".hrf": content = "application/x-hrf"; break;
                case ".htc": content = "text/x-component"; break;
                case ".html": content = "text/html"; break;
                case ".htx": content = "text/html"; break;
                case ".ico": content = "image/x-icon"; break;
                case ".iff": content = "application/x-iff"; break;
                case ".igs": content = "application/x-igs"; break;
                case ".img": content = "application/x-img"; break;
                case ".isp": content = "application/x-internet-signup"; break;
                case ".java": content = "java/*"; break;
                case ".jpeg": content = "image/jpeg"; break;
                case ".jsp": content = "text/html"; break;
                case ".lar": content = "application/x-laplayer-reg"; break;
                case ".lavs": content = "audio/x-liquid-secure"; break;
                case ".lmsff": content = "audio/x-la-lms"; break;
                case ".ltr": content = "application/x-ltr"; break;
                case ".m2v": content = "video/x-mpeg"; break;
                case ".m4e": content = "video/mpeg4"; break;
                case ".man": content = "application/x-troff-man"; break;
                case ".mdb": content = "application/msaccess"; break;
                case ".mfp": content = "application/x-shockwave-flash"; break;
                case ".mhtml": content = "message/rfc822"; break;
                case ".mid": content = "audio/mid"; break;
                case ".mil": content = "application/x-mil"; break;
                case ".mnd": content = "audio/x-musicnet-download"; break;
                case ".mocha": content = "application/x-javascript"; break;
                case ".mp1": content = "audio/mp1"; break;
                case ".mp2v": content = "video/mpeg"; break;
                case ".mp4": content = "video/mpeg4"; break;
                case ".mpd": content = "application/vnd.ms-project"; break;
                case ".mpeg": content = "video/mpg"; break;
                case ".mpga": content = "audio/rn-mpeg"; break;
                case ".mps": content = "video/x-mpeg"; break;
                case ".mpv": content = "video/mpg"; break;
                case ".mpw": content = "application/vnd.ms-project"; break;
                case ".mtx": content = "text/xml"; break;
                case ".net": content = "image/pnetvue"; break;
                case ".nws": content = "message/rfc822"; break;
                case ".out": content = "application/x-out"; break;
                case ".p12": content = "application/x-pkcs12"; break;
                case ".p7c": content = "application/pkcs7-mime"; break;
                case ".p7r": content = "application/x-pkcs7-certreqresp"; break;
                case ".pc5": content = "application/x-pc5"; break;
                case ".pcl": content = "application/x-pcl"; break;
                case ".pdf": content = "application/pdf"; break;
                case ".pdx": content = "application/vnd.adobe.pdx"; break;
                case ".pgl": content = "application/x-pgl"; break;
                case ".pko": content = "application/vnd.ms-pki.pko"; break;
                case ".plg": content = "text/html"; break;
                case ".plt": content = "application/x-plt"; break;

                case ".ppa": content = "application/vnd.ms-powerpoint"; break;
                case ".pps": content = "application/vnd.ms-powerpoint"; break;

                case ".prf": content = "application/pics-rules"; break;
                case ".prt": content = "application/x-prt"; break;

                case ".pwz": content = "application/vnd.ms-powerpoint"; break;
                case ".ra": content = "audio/vnd.rn-realaudio"; break;
                case ".ras": content = "application/x-ras"; break;
                case ".rdf": content = "text/xml"; break;
                case ".red": content = "application/x-red"; break;
                case ".rjs": content = "application/vnd.rn-realsystem-rjs"; break;
                case ".rlc": content = "application/x-rlc"; break;
                case ".rm": content = "application/vnd.rn-realmedia"; break;
                case ".rmi": content = "audio/mid"; break;
                case ".rmm": content = "audio/x-pn-realaudio"; break;
                case ".rms": content = "application/vnd.rn-realmedia-secure"; break;
                case ".rmx": content = "application/vnd.rn-realsystem-rmx"; break;
                case ".rp": content = "image/vnd.rn-realpix"; break;
                case ".rsml": content = "application/vnd.rn-rsml"; break;
                case ".rtf": content = "application/msword"; break;
                case ".rv": content = "video/vnd.rn-realvideo"; break;
                case ".sat": content = "application/x-sat"; break;
                case ".sdw": content = "application/x-sdw"; break;
                case ".slb": content = "application/x-slb"; break;
                case ".slk": content = "drawing/x-slk"; break;
                case ".smil": content = "application/smil"; break;
                case ".snd": content = "audio/basic"; break;
                case ".sor": content = "text/plain"; break;
                case ".spl": content = "application/futuresplash"; break;
                case ".ssm": content = "application/streamingmedia"; break;
                case ".stl": content = "application/vnd.ms-pki.stl"; break;
                case ".sty": content = "application/x-sty"; break;
                case ".swf": content = "application/x-shockwave-flash"; break;
                case ".tg4": content = "application/x-tg4"; break;

                case ".tiff": content = "image/tiff"; break;
                case ".top": content = "drawing/x-top"; break;
                case ".tsd": content = "text/xml"; break;
                case ".uin": content = "application/x-icq"; break;
                case ".vcf": content = "text/x-vcard"; break;
                case ".vdx": content = "application/vnd.visio"; break;
                case ".vpg": content = "application/x-vpeg005"; break;

                case ".vst": content = "application/vnd.visio"; break;
                case ".vsw": content = "application/vnd.visio"; break;
                case ".vtx": content = "application/vnd.visio"; break;
                case ".wav": content = "audio/wav"; break;
                case ".wb1": content = "application/x-wb1"; break;
                case ".wb3": content = "application/x-wb3"; break;
                case ".wiz": content = "application/msword"; break;
                case ".wk4": content = "application/x-wk4"; break;
                case ".wks": content = "application/x-wks"; break;
                case ".wma": content = "audio/x-ms-wma"; break;
                case ".wmf": content = "application/x-wmf"; break;
                case ".wmv": content = "video/x-ms-wmv"; break;
                case ".wmz": content = "application/x-ms-wmz"; break;
                case ".wpd": content = "application/x-wpd"; break;
                case ".wpl": content = "application/vnd.ms-wpl"; break;
                case ".wr1": content = "application/x-wr1"; break;
                case ".wrk": content = "application/x-wrk"; break;
                case ".ws2": content = "application/x-ws"; break;
                case ".wsdl": content = "text/xml"; break;
                case ".xdp": content = "application/vnd.adobe.xdp"; break;
                case ".xfd": content = "application/vnd.adobe.xfd"; break;
                case ".xhtml": content = "text/html"; break;

                case ".xml": content = "text/xml"; break;
                case ".xq": content = "text/xml"; break;
                case ".xquery": content = "text/xml"; break;
                case ".xsl": content = "text/xml"; break;
                case ".xwd": content = "application/x-xwd"; break;
                case ".sis": content = "application/vnd.symbian.install"; break;
                case ".x_t": content = "application/x-x_t"; break;
                case ".apk": content = "application/vnd.android.package-archive"; break;

                case ".301": content = "application/x-301"; break;
                case ".906": content = "application/x-906"; break;
                case ".a11": content = "application/x-a11"; break;
                case ".ai": content = "application/postscript"; break;
                case ".aifc": content = "audio/aiff"; break;
                case ".anv": content = "application/x-anv"; break;
                case ".asf": content = "video/x-ms-asf"; break;
                case ".asx": content = "video/x-ms-asf"; break;
                case ".avi": content = "video/avi"; break;
                case ".biz": content = "text/xml"; break;
                case ".bot": content = "application/x-bot"; break;
                case ".c90": content = "application/x-c90"; break;
                case ".cat": content = "application/vnd.ms-pki.seccat"; break;
                case ".cdr": content = "application/x-cdr"; break;
                case ".cer": content = "application/x-x509-ca-cert"; break;
                case ".cgm": content = "application/x-cgm"; break;
                case ".class": content = "java/*"; break;
                case ".cmp": content = "application/x-cmp"; break;
                case ".cot": content = "application/x-cot"; break;
                case ".crt": content = "application/x-x509-ca-cert"; break;
                case ".css": content = "text/css"; break;
                case ".dbf": content = "application/x-dbf"; break;
                case ".dbx": content = "application/x-dbx"; break;
                case ".dcx": content = "application/x-dcx"; break;
                case ".dgn": content = "application/x-dgn"; break;
                case ".dll": content = "application/x-msdownload"; break;
                case ".dot": content = "application/msword"; break;
                case ".dtd": content = "text/xml"; break;
                case ".dwf": content = "application/x-dwf"; break;
                case ".dxb": content = "application/x-dxb"; break;
                case ".edn": content = "application/vnd.adobe.edn"; break;
                case ".eml": content = "message/rfc822"; break;
                case ".epi": content = "application/x-epi"; break;
                case ".exe": content = "application/x-msdownload"; break;
                case ".fdf": content = "application/vnd.fdf"; break;
                case ".fo": content = "text/xml"; break;
                case ".g4": content = "application/x-g4"; break;
                case ".": content = "application/x-"; break;
                case ".gl2": content = "application/x-gl2"; break;
                case ".hgl": content = "application/x-hgl"; break;
                case ".hpg": content = "application/x-hpgl"; break;
                case ".hqx": content = "application/mac-binhex40"; break;
                case ".hta": content = "application/hta"; break;
                case ".htm": content = "text/html"; break;
                case ".htt": content = "text/webviewhtml"; break;
                case ".icb": content = "application/x-icb"; break;
                case ".ig4": content = "application/x-g4"; break;
                case ".iii": content = "application/x-iphone"; break;
                case ".ins": content = "application/x-internet-signup"; break;
                case ".IVF": content = "video/x-ivf"; break;
                case ".jfif": content = "image/jpeg"; break;
                case ".jpe": content = "application/x-jpe"; break;
                case ".jpg": content = "image/jpeg"; break;
                case ".js": content = "application/x-javascript"; break;
                case ".la1": content = "audio/x-liquid-file"; break;
                case ".latex": content = "application/x-latex"; break;
                case ".lbm": content = "application/x-lbm"; break;
                case ".ls": content = "application/x-javascript"; break;
                case ".m1v": content = "video/x-mpeg"; break;
                case ".m3u": content = "audio/mpegurl"; break;
                case ".mac": content = "application/x-mac"; break;
                case ".math": content = "text/xml"; break;
                case ".mht": content = "message/rfc822"; break;
                case ".mi": content = "application/x-mi"; break;
                case ".midi": content = "audio/mid"; break;
                case ".mml": content = "text/xml"; break;
                case ".mns": content = "audio/x-musicnet-stream"; break;
                case ".movie": content = "video/x-sgi-movie"; break;
                case ".mp2": content = "audio/mp2"; break;
                case ".mp3": content = "audio/mp3"; break;
                case ".mpa": content = "video/x-mpg"; break;
                case ".mpe": content = "video/x-mpeg"; break;
                case ".mpg": content = "video/mpg"; break;
                case ".mpp": content = "application/vnd.ms-project"; break;
                case ".mpt": content = "application/vnd.ms-project"; break;
                case ".mpv2": content = "video/mpeg"; break;
                case ".mpx": content = "application/vnd.ms-project"; break;
                case ".mxp": content = "application/x-mmxp"; break;
                case ".nrf": content = "application/x-nrf"; break;
                case ".odc": content = "text/x-ms-odc"; break;
                case ".p10": content = "application/pkcs10"; break;
                case ".p7b": content = "application/x-pkcs7-certificates"; break;
                case ".p7m": content = "application/pkcs7-mime"; break;
                case ".p7s": content = "application/pkcs7-signature"; break;
                case ".pci": content = "application/x-pci"; break;
                case ".pcx": content = "application/x-pcx"; break;

                case ".pfx": content = "application/x-pkcs12"; break;
                case ".pic": content = "application/x-pic"; break;
                case ".pl": content = "application/x-perl"; break;
                case ".pls": content = "audio/scpls"; break;
                case ".png": content = "image/png"; break;
                case ".pot": content = "application/vnd.ms-powerpoint"; break;
                case ".ppm": content = "application/x-ppm"; break;
                case ".ppt": content = "application/vnd.ms-powerpoint"; break;
                case ".pr": content = "application/x-pr"; break;
                case ".prn": content = "application/x-prn"; break;
                case ".ps": content = "application/x-ps"; break;
                case ".ptn": content = "application/x-ptn"; break;
                case ".r3t": content = "text/vnd.rn-realtext3d"; break;
                case ".ram": content = "audio/x-pn-realaudio"; break;
                case ".rat": content = "application/rat-file"; break;
                case ".rec": content = "application/vnd.rn-recording"; break;
                case ".rgb": content = "application/x-rgb"; break;
                case ".rjt": content = "application/vnd.rn-realsystem-rjt"; break;
                case ".rle": content = "application/x-rle"; break;
                case ".rmf": content = "application/vnd.adobe.rmf"; break;
                case ".rmj": content = "application/vnd.rn-realsystem-rmj"; break;
                case ".rmp": content = "application/vnd.rn-rn_music_package"; break;
                case ".rmvb": content = "application/vnd.rn-realmedia-vbr"; break;
                case ".rnx": content = "application/vnd.rn-realplayer"; break;
                case ".rpm": content = "audio/x-pn-realaudio-plugin"; break;
                case ".rt": content = "text/vnd.rn-realtext"; break;

                case ".sam": content = "application/x-sam"; break;
                case ".sdp": content = "application/sdp"; break;
                case ".sit": content = "application/x-stuffit"; break;
                case ".sld": content = "application/x-sld"; break;
                case ".smi": content = "application/smil"; break;
                case ".smk": content = "application/x-smk"; break;
                case ".sol": content = "text/plain"; break;
                case ".spc": content = "application/x-pkcs7-certificates"; break;
                case ".spp": content = "text/xml"; break;
                case ".sst": content = "application/vnd.ms-pki.certstore"; break;
                case ".stm": content = "text/html"; break;
                case ".svg": content = "text/xml"; break;
                case ".tdf": content = "application/x-tdf"; break;
                case ".tga": content = "application/x-tga"; break;
                case ".tif": content = "application/x-tif"; break;
                case ".tld": content = "text/xml"; break;
                case ".torrent": content = "application/x-bittorrent"; break;
                case ".txt": content = "text/plain"; break;
                case ".uls": content = "text/iuls"; break;
                case ".vda": content = "application/x-vda"; break;
                case ".vml": content = "text/xml"; break;
                case ".vsd": content = "application/vnd.visio"; break;
                case ".vss": content = "application/vnd.visio"; break;

                case ".vsx": content = "application/vnd.visio"; break;
                case ".vxml": content = "text/xml"; break;
                case ".wax": content = "audio/x-ms-wax"; break;
                case ".wb2": content = "application/x-wb2"; break;
                case ".wbmp": content = "image/vnd.wap.wbmp"; break;
                case ".wk3": content = "application/x-wk3"; break;
                case ".wkq": content = "application/x-wkq"; break;
                case ".wm": content = "video/x-ms-wm"; break;
                case ".wmd": content = "application/x-ms-wmd"; break;
                case ".wml": content = "text/vnd.wap.wml"; break;
                case ".wmx": content = "video/x-ms-wmx"; break;
                case ".wp6": content = "application/x-wp6"; break;
                case ".wpg": content = "application/x-wpg"; break;
                case ".wq1": content = "application/x-wq1"; break;
                case ".wri": content = "application/x-wri"; break;
                case ".ws": content = "application/x-ws"; break;
                case ".wsc": content = "text/scriptlet"; break;
                case ".wvx": content = "video/x-ms-wvx"; break;
                case ".xdr": content = "text/xml"; break;
                case ".xfdf": content = "application/vnd.adobe.xfdf"; break;
                case ".xls": content = "application/vnd.ms-excel"; break;
                case ".csv": content = "application/vnd.ms-excel"; break;
                case ".xlw": content = "application/x-xlw"; break;
                case ".xpl": content = "audio/scpls"; break;
                case ".xql": content = "text/xml"; break;
                case ".xsd": content = "text/xml"; break;
                case ".xslt": content = "text/xml"; break;
                case ".x_b": content = "application/x-x_b"; break;
                case ".sisx": content = "application/vnd.symbian.install"; break;
                case ".ipa": content = "application/vnd.iphone"; break;
                case ".xap": content = "application/x-silverlight-app"; break;
                case ".xlsx": content = "application/vnd.ms-excel"; break;
                case ".rar": content = "application/x-rar-compressed"; break;
                case ".zip": content = "application/zip"; break;
                case ".msg": content = "application/msword"; break;
                default: content = "application/msword"; break;

            }
            return content;
        }
    }
}
